package com.kuqi.config;

/**
 * @author:kuqi
 * @createTime:2021/11/9 15:05
 * @description:后端发送给前端在这里打包，相当于vo
 */

/**
 * code:编号
 * msg:信息
 * data<T>:封装任意类型的对象到data属性中
 * @param <T>
 */
public class Result<T>{
    private String code;
    private String msg;
    private T data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result success(){
        Result result = new Result();
        result.setCode("0");
        result.setMsg("成功");
        return  result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result();
        result.setCode("0");
        result.setMsg("成功");
        result.setData(data);
        return  result;
    }

    public static Result error(String code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return  result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
